package com.bw.user.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.bw.user.entity.HouseUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName UserController
 * @Author Hao_YunKai
 * @Date 2022/3/25 19:41
 */
@Controller
public class UserController {
    @Autowired
    private StringRedisTemplate redisTemplate;

    @Autowired
    private HttpServletRequest request;

    @GetMapping(path = {"/","/login"})
    public String login() {
        return "user_login";
    }

    @GetMapping(path = "order")
    public String order(Model model) {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            if ("token".equals(cookie.getName())) {
                String user = redisTemplate.opsForValue().get(cookie.getValue());
                HouseUserEntity userEntity = JSON.parseObject(user, new TypeReference<HouseUserEntity>() {
                });

            }
        }
        return "user_order";
    }


    @GetMapping(path = "/user_register")
    public String user_register() {
        return "user_register";
    }

    @GetMapping("zufang")
    public String zufang() {
        return "redirect:http://localhost:8001/zufang.html";
    }

    // 修改个人资料
    @GetMapping ("editProfile")
    public String editProfile() {
        return "edit_profile";
    }
}
